package algorithms.dynamicProgram;

import java.util.concurrent.ConcurrentHashMap;

public class LeetCode_322 {

    public static void main(String[] args) {
        int[] ints = {1, 2, 5};
        System.out.println(coinChange(ints, 11));
    }

    public static int coinChange(int[] coins, int amount) {
        // 自底向上的动态规划
        if (coins.length == 0) {
            return -1;
        }
        int[] dp = new int[amount + 1];
        dp[0] = 0;
        for (int i = 1; i <= amount; i++) {
            dp[i] = amount+1;
            for (int j = 0; j < coins.length; j++) {
                if (coins[j] <= i) {
                    dp[i] = Math.min(dp[i], dp[i - coins[j]] + 1);
                }
            }
        }
        return dp[amount] > amount ? -1 : dp[amount];
    }
}
